<template>
  <div class="org-container">
    <!-- 页面标题 -->
    <div class="org-header fade-in-section">
      <h2>团队组织架构</h2>
      <p>TEAM ORGANIZATION STRUCTURE</p>
    </div>
    <!-- 核心内容区：纵向三行布局（每行=标题+横向成员） -->
    <div class="org-content">
      <!-- 1. 实验室主任行：标题 + 横向成员 -->
      <div class="org-row fade-in-section">
        <h3 class="row-title">实验室主任</h3>
        <div class="member-cards horizontal-cards">
          <div class="member-card" v-for="member in directorMembers" :key="member.id" @click="goToMember(member)">
            <div class="member-avatar">
              <img :src="member.avatar" :alt="member.name" />
            </div>
            <div class="member-info">
              <h4>{{ member.name }}</h4>
              <p class="position">{{ member.position }}</p>
              <p class="dept">{{ getDeptName(member.dept) }}</p>
            </div>
          </div>
        </div>
      </div>
      <!-- 2. 学术委员会行：标题 + 横向成员 -->
      <div class="org-row fade-in-section">
        <h3 class="row-title">学术委员会</h3>
        <div class="member-cards horizontal-cards">
          <div
            class="member-card"
            v-for="member in academicMembers"
            :key="member.id"
            @click="goToProfessor(member.url)"
          >
            <div class="member-avatar">
              <img :src="member.avatar" :alt="member.name" />
            </div>
            <div class="member-info">
              <h4>{{ member.name }}</h4>
              <p class="position">{{ member.position }}</p>
              <p class="dept">{{ getDeptName(member.dept) }}</p>
            </div>
          </div>
        </div>
      </div>
      <!-- 3. 主要成员行：标题 + 横向成员 -->
      <div class="org-row fade-in-section">
        <h3 class="row-title">主要成员</h3>
        <div class="member-cards horizontal-cards">
          <div class="member-card" v-for="member in coreMembers" :key="member.id" @click="goToMain(member)">
            <div class="member-avatar">
              <img :src="member.avatar" :alt="member.name" />
            </div>
            <div class="member-info">
              <h4>{{ member.name }}</h4>
              <p class="position">{{ member.position }}</p>
              <p class="dept">{{ getDeptName(member.dept) }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      memberType: 'all',
      departments: {
        // 'director': '实验室主任',
        // 'academic': '学术委员会',
        // 'core': '主要成员'
      },
      members: [
        // 实验室主任
        {
          id: 1,
          name: '张鹏',
          position: '主任',
          type: 'director',
          dept: 'director',
          avatar: require('@/assets/img/zhangpeng.png'),
          route: 'researchTeam/teacherZhang'
        },
        // 学术委员会
        {
          id: 2,
          name: '雷为民',
          position: '客座教授',
          type: 'academic',
          dept: 'academic',
          avatar: require('@/assets/img/leiweimin.png'),
          url: 'http://www.cse.neu.edu.cn/2019/0313/c6667a159530/page.htm'
        },
        {
          id: 3,
          name: '付冲',
          position: '客座教授',
          type: 'academic',
          dept: 'academic',
          avatar: require('@/assets/img/fuchong.webp'),
          url: 'http://www.cse.neu.edu.cn/2019/0314/c6641a157526/page.htm'
        },
        {
          id: 4,
          name: '杨海波',
          position: '客座教授',
          type: 'academic',
          dept: 'academic',
          avatar: require('@/assets/img/yanghaibo.jpg'),
          url: 'https://sise.sut.edu.cn/info/1056/1244.htm'
        },
        {
          id: 5,
          name: '贾军营',
          position: '客座教授',
          type: 'academic',
          dept: 'academic',
          avatar: require('@/assets/img/jiajunying.jpg'),
          url: 'https://sise.sut.edu.cn/info/1056/1246.htm'
        },
        // 主要成员
        {
          id: 6,
          name: '董克',
          position: '人工智能专家',
          type: 'core',
          dept: 'core',
          avatar: require('@/assets/img/dongke.jpg'),
          route: 'researchTeam/213DongKe'

        },
        {
          id: 7,
          name: '赵新蕾',
          position: '学术负责人',
          type: 'core',
          dept: 'core',
          avatar: require('@/assets/img/zhaoxinlei.jpg'),
          route: 'researchTeam/213ZhaoXinLei'
        },
        {
          id: 8,
          name: '李志超',
          position: '系统架构师',
          type: 'core',
          dept: 'core',
          avatar: require('@/assets/img/lizhichao.png'),
          route: 'researchTeam/213LiZhiChao'
        },
        {
          id: 9,
          name: '董力嘉',
          position: '算法架构师',
          type: 'core',
          dept: 'core',
          avatar: require('@/assets/img/donglijia.jpg'),
          route: 'researchTeam/213DongLijia'
        }
      ]
    };
  },
  computed: {
    filteredMembers() {
      return this.members.filter(member => {
        const typeMatch = this.memberType === 'all' ? true : member.type === this.memberType;
        return typeMatch;
      });
    },
    directorMembers() {
      return this.filteredMembers.filter(m => m.type === 'director');
    },
    academicMembers() {
      return this.filteredMembers.filter(m => m.type === 'academic');
    },
    coreMembers() {
      return this.filteredMembers.filter(m => m.type === 'core');
    }
  },
  methods: {
    getDeptName(deptId) {
      return this.departments[deptId] || '';
    },
    goToMember(member) {
      this.$router.push(member.route);
    },
    goToProfessor(url) {
      window.open(url, '_blank');
    },
    goToMain(member) {
      this.$router.push(member.route);
    },
    checkFadeIn() {
      // 获取所有需要添加渐入效果的元素
      const fadeElements = document.querySelectorAll('.fade-in-section');

      fadeElements.forEach(element => {
        // 获取元素位置信息
        const elementTop = element.getBoundingClientRect().top;
        const elementBottom = element.getBoundingClientRect().bottom;

        // 当元素顶部进入视口底部100px时，或元素底部进入视口顶部时，添加显示类
        const isVisible = (elementTop < window.innerHeight - 100) && (elementBottom > 0);

        if (isVisible) {
          element.classList.add('is-visible');
        }
      });
    }
  },
  mounted() {
    // 初始检查一次
    this.checkFadeIn();
    // 监听滚动事件
    window.addEventListener('scroll', this.checkFadeIn);
  },
  beforeDestroy() {
    // 移除事件监听，防止内存泄漏
    window.removeEventListener('scroll', this.checkFadeIn);
  }
};
</script>
<style scoped>
/* 页面容器样式 */
.org-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 40px 20px;
}
/* 页面标题样式 */
.org-header {
  text-align: center;
  margin-bottom: 40px;
  color: #333;
}
.org-header h2 {
  font-size: 28px;
  margin: 0 0 10px;
}
.org-header p {
  font-size: 14px;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #666;
}
/* 核心内容区：纵向三行布局 */
.org-content {
  display: flex;
  flex-direction: column;
  gap: 30px;
}
/* 每行容器：标题+横向成员 */
.org-row {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 15px;
  background-color: #f9fafb;
  border-radius: 8px;
}
/* 行标题样式（原列标题调整） */
.row-title {
  font-size: 18px;
  color: #333;
  margin: 0;
  padding: 8px 16px;
  background-color: #0056d2;
  color: white;
  border-radius: 4px;
  white-space: nowrap;
}
/* 横向成员卡片组：横向滚动（小屏幕时） */
.horizontal-cards {
  display: flex;
  gap: 15px;
  overflow-x: auto;
  padding: 10px 0;
  flex: 1;
}
/* 隐藏滚动条（优化视觉） */
.horizontal-cards::-webkit-scrollbar {
  height: 6px;
}
.horizontal-cards::-webkit-scrollbar-thumb {
  background-color: #ddd;
  border-radius: 3px;
}
/* 成员卡片样式（保持原有设计） */
.member-card {
  display: flex;
  gap: 15px;
  padding: 18px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  min-width: 280px; /* 保证卡片不被压缩 */
  cursor: pointer;
}
.member-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
/* 头像样式 */
.member-avatar img {
  width: 80px;
  height: 80px;
  border-radius: 20%;
  object-fit: cover;
}
/* 卡片信息样式 */
.member-info {
  flex: 1;
}
.member-info h4 {
  font-size: 18px;
  color: #333;
  margin: 0 0 8px;
}
.position {
  font-size: 15px;
  color: #0056d2;
  margin: 15px 0 5px;
}
.dept {
  font-size: 12px;
  color: #666;
  margin: 0;
}
/* 响应式适配：小屏幕下优化 */
@media (max-width: 768px) {
  .org-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .row-title {
    margin-bottom: 10px;
  }
  .member-card {
    min-width: 100%;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
}

/* 滚动渐入效果样式 */
.fade-in-section {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
  will-change: opacity, transform;
}

.fade-in-section.is-visible {
  opacity: 1;
  transform: translateY(0);
}
</style>